import Game
import unittest

class GameTestCases(unittest.TestCase):
    def test_horiztal_link(self):
        game = Game.game()
        for i in range(5):
            game.ground[i][1] = Game.piece_p1

        piece = Game.pieceposition()
        piece.x =2
        piece.y = 1
        self.assertTrue(game.GetFullLineLengthOfPostion(piece) == 5)
        piece.x =2
        piece.y = 2
        self.assertEqual(game.GetFullLineLengthOfPostion(piece), 0)

    def test_vertical_link(self):
        game = Game.game()
        for i in range(5):
            game.ground[1][i] = Game.piece_p1

        piece = Game.pieceposition()
        piece.x =1
        piece.y = 3
        self.assertTrue(game.GetFullLineLengthOfPostion(piece) == 5)

        piece.x =2
        piece.y = 3
        self.assertTrue(game.GetFullLineLengthOfPostion(piece) < 2)

    def test_bevel_link(self):
        game = Game.game()
        piece = Game.pieceposition()
        piece.x = 1
        piece.y = 1
        game.ground[2][0] = Game.piece_p1
        game.ground[1][1] = Game.piece_p1
        game.ground[0][2] = Game.piece_p1
        self.assertEqual(game.GetFullLineLengthOfPostion(piece) , 3)

        game.ground[2][0] = Game.piece_p1
        game.ground[3][1] = Game.piece_p1
        game.ground[4][2] = Game.piece_p1
        piece.x = 4
        piece.y = 2
        self.assertEqual(game.GetFullLineLengthOfPostion(piece) , 3)

        game.ground[4][0] = Game.piece_p1
        game.ground[3][1] = Game.piece_p1
        game.ground[2][2] = Game.piece_p1
        game.ground[1][3] = Game.piece_p1
        game.ground[0][4] = Game.piece_p1
        piece.x = 3
        piece.y = 1
        self.assertEqual(game.GetFullLineLengthOfPostion(piece) , 5)

    def test_input_full(self):
        game = Game.game()
        for i in range(5):
            for j in range(5):
                game.ground[i][j] = Game.piece_p1
        game.ground[2][2] = Game.piece_empty
        game.state = Game.state_input
        piece = Game.pieceposition()
        piece.x = 2
        piece.y = 2
        game.SetPiece(piece)
        self.assertEqual(game.state, Game.state_over)

    def test_catch_all(self):
        game = Game.game()
        for i in range(5):
            for j in range(5):
                game.ground[i][j] = Game.piece_p1
        game.ground[2][2] = Game.piece_empty
        game.ground[0][0] = Game.piece_p2
        game.ground[1][0] = Game.piece_p2
        game.state = Game.state_input
        piece = Game.pieceposition()
        piece.x = 2
        piece.y = 2
        game.SetPiece(piece)
        piece.x = 0
        piece.y = 0
        game.Catch(piece)
        piece.x = 1
        piece.y = 0
        game.Catch(piece)
        self.assertEqual(game.state, Game.state_over)

if __name__ == '__main__':
    unittest.main()